var app = getApp();
const URL = app.globalData.URL;

let orderList = [
  {
    state: '租赁中',
    sum: '1096.00',
    total: 1,
    title: '租满即送（含电池租金）',
    description: '套餐：租满即送（含电池租金）6个月',
    zq:'2023.7.21-2024.1.21',
    price: '499.00',
    num: '1',
    image:URL+'/admin-api/infra/file/4/get/b3a10951f9307d6b22e4f3880e2ff2fcd267d4fe68456077ded7a7d76f5e01ae.png',
  }
];

Page({
  data: {
    tabs: ['租赁中'],
    activeTab: 0, 
    titleOpacity: 1,
    shadow: false,
    orderList: orderList,
    id:null,
    order:null
  },
  onLoad() {
    let params = my.getStorageSync({ key: 'params_order' }).data;
    console.log(params.orderId);  // 输出：value1
    this.setData({id:params.orderId});

    my.httpRequest({
      url: `${URL}/app-api/chl/order/get2`,
      data: {
        id:this.data.id,
      },
      headers:{"tenant-id":"1",
      'content-type': 'application/x-www-form-urlencoded'},
      success: (res) => {
        this.setData({order:res.data.data});
        var order = res.data.data;
        console.log(this.data.order);
      },
      fail: (err) => {
        console.log(err);
      }
    });

  },
  onBill(){
    my.navigateTo({url:"/pages/order/bill/bill?orderSn="+this.data.order.orderSn});
  },
  //联系租户
  lxzh(){
    my.makePhoneCall(
      {
      number: '17797713158', 
      success: function(res) 
      {
       console.log(res); //{"success": true} 
      },
      fail: function(err) {
        console.log(err); 
      }
      }
      );

  },
  onTabBarTap(e) {
    const { index } = e.target.dataset
    let sList = []
    if(index == 0){
      sList = orderList
    }else if(index == 1){
      sList[0] = orderList[0]
    }else if(index == 2){
      sList[0] = orderList[1]
    }else if(index == 3){
      sList[0] = orderList[2]
    }else if(index == 4){
      sList[0] = orderList[3]
    }else if(index == 5){
      sList[0] = orderList[4]
    }
    this.setData({
      activeTab: index,
      orderList: sList
    });
  },
});
